<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Chain</title>
</head>
<body>
    <button onclick="test1()">请求</button>
<br/>
    <div id="result"></div>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.20.0/axios.js"></script>
    <script>
        const resutl = document.getElementById('result');

        axios.interceptors.request.use(
            config => {
                console.log('request interceptor1 OnResolved', config);
                return config;
            }, 
            error => {
                console.log('request interceptor1 OnRejected', error);
                return Promise.reject(error);
            }
        )
        axios.interceptors.request.use(
            config => {
                console.log('request interceptor2 OnResolved', config);
                return config;
            }, 
            error => {
                console.log('request interceptor2 OnRejected', error);
                return Promise.reject(error);
            }
        )
        
        axios.interceptors.response.use(
            response => {
                console.log('response interceptor1 Onresolved.', response);
                return response;
            },
            error => {
                console.log('response interceptor1 OnRejected.', error);
                return Promise.reject(error);
            }
        )

        axios.interceptors.response.use(
            response => {
                console.log('response interceptor2 Onresolved.', response);
                return response;
            },
            error => {
                console.log('response interceptor2 OnRejected.', error);
                return Promise.reject(error);
            }
        )



        axios.defaults.baseURL = 'http://localhost:9001'
        function test1(params){
            axios({
                url:'/posts',
                params: {
                    id: 1
                }
            }).then(response => {
                console.log('data----', response);
                resutl.innerText = JSON.stringify(response.data);
            }).catch(error => {
                console.log(error);
            });
        }

    </script>

</body>
</html>